﻿using Anke.SHManage.Model;
using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class IMBalanceTotalModeWebForm : System.Web.UI.Page
    {
 
        //string type = "MaterialType-13','MaterialType-14','MaterialType-15','MaterialType-16','MaterialType-17','MaterialType-18','MaterialType-19','MaterialType-20','MaterialType-22','MaterialType-23','MaterialType-24','MaterialType-25','MaterialType-21','MaterialType-26";
        //string reportName = "药品器械月报表";
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                //this.TextMonth.Text = DateTime.Now.Year + DateTime.Now.AddMonths(-1).ToString("MM");
                //Data_Binding(type,reportName);
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }
        private void InitPage()
        {
            this.TextMonth.Text = DateTime.Now.Year + DateTime.Now.AddMonths(-1).ToString("MM");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
        }
        //private void Data_Binding(string type,string reportName)
        private void BindReportDataSource()
        {

            string month = this.TextMonth.Text;
            string reportMonth = month.ToString();
            //string newtype = type;
            //string newReportName = reportName;

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            //this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/TJ_IMBalanceTotal.rdlc");
            Microsoft.Reporting.WebForms.ReportParameter m = new Microsoft.Reporting.WebForms.ReportParameter("ReportMonth", reportMonth);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { m });
            TJDAL dal = new TJDAL();
            switch (reportName)
            {
                case "TJ_IMBalanceYPQXTotal.rdlc":
                    this.Page.Title = "药品器械月报表";
                    DataTable dt1 = dal.Get_BalanceYPQXTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_IMBalanceYPQXTotal", dt1));
                    break;
                case "TJ_IMBalanceQPTotal.rdlc":
                    this.Page.Title = "汽车配件月报表";
                    DataTable dt2 = dal.Get_BalanceQPTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_IMBalanceQPTotal", dt2));
                    break;
                //2018-10-24 dyq
                case "TJ_QPKF.rdlc":
                    this.Page.Title = "汽配库房盘点月报表";
                    DataTable dt3 = dal.Get_BalanceQPTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt3));
                    break;
                //2018-10-24 dyq
                case "TJ_RYPKF.rdlc":
                    this.Page.Title = "日用品库房盘点月报表";
                    DataTable dt4 = dal.Get_BalanceRYPTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetTJ_RYPKF", dt4));
                    break;
                //2018-10-24 dyq
                case "TJ_FZYPQXLY.rdlc":
                    this.Page.Title = "药品材料器械分站领用明细表";
                    DataTable dt5 = dal.Get_StationYPQXTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetTJ_FZYPQXLY", dt5));
                    break;
                //2018-10-24 dyq
                case "TJ_FZQPLY.rdlc":
                    this.Page.Title = "分站汽配领用明细表";
                    DataTable dt6 = dal.Get_StationQPTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetTJ_FZQPLY", dt6));
                    break;
                //2018-10-24 dyq
                case "TJ_FZRYPLY.rdlc":
                    this.Page.Title = "分站日用品领用明细表";
                    DataTable dt7 = dal.Get_StationRYPTotal(month);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetTJ_FZRYPLY", dt7));
                    break;
                default:
                    break;
            }
            //DataTable dt = dal.Get_BalanceTotal(month, newtype);
            //this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_BalanceTotal", dt));
            this.ReportViewer1.LocalReport.Refresh();
        }

        //protected void btnDrug_Click(object sender, EventArgs e)
        //{
        //    //TJDAL dal = new TJDAL();
        //    // List<CheckModelExt> list = dal.getlistbypid();
        //    //将以下取string 写活。
        //    TJDAL dal = new TJDAL();
        //    List<CheckModelExt> lm = dal.GetTDictionaryIDByParentID("MaterialType-12");       
        //    string ret = "";
        //    for (int i = 0; i < lm.Count; i++)
        //    {
        //        ret += lm[i].ID.ToString() + "','";
        //    }
        //    ret = ret.TrimEnd(',');

        //    type = ret;
        //    reportName = "药品器械月报表";
        //    Data_Binding(type,reportName);
        //}

        //protected void btnCar_Click(object sender, EventArgs e)
        //{
        //    TJDAL dal = new TJDAL();
        //    List<CheckModelExt> lm = dal.GetTDictionaryIDByParentID("MaterialType-9999");

        //    string ret = "";
        //    for (int i = 0; i < lm.Count; i++)
        //    {
        //        ret += lm[i].ID.ToString() + "','";
        //    }
        //    ret = ret.TrimEnd(',');

        //    type = ret;
        //    reportName = "汽车配件月报表";
        //    Data_Binding(type,reportName);
        //}
    }
}